package randx

// UpperAlphaStr 生成全是大写字母组成的指定长度的字符串
func UpperAlphaStr(length int) string {
	return string(bytesMultiRange(length, [2]byte{'A', 'Z' + 1}))
}

// LowerAlphaStr 生成全是小写字母组成的指定长度的字符串
func LowerAlphaStr(length int) string {
	return string(bytesMultiRange(length, [2]byte{'a', 'z' + 1}))
}

// AlphaStr 生成全是字母组成的指定长度的字符串
func AlphaStr(length int) string {
	return string(bytesMultiRange(length, [2]byte{'A', 'Z' + 1}, [2]byte{'a', 'z' + 1}))
}

// DigitStr 生成全是数字(0-9)组成的指定长度的字符串
func DigitStr(length int) string {
	return string(bytesMultiRange(length, [2]byte{'0', '9' + 1}))
}

// AlphaDigitStr 生成字母和数字组成的指定长度的字符串
func AlphaDigitStr(length int) string {
	return string(bytesMultiRange(length, [2]byte{'a', 'z' + 1}, [2]byte{'A', 'Z' + 1}, [2]byte{'0', '9' + 1}))
}

// PrintableASCII 生成随机的可打印 ASCII 指定长度的字符串
func PrintableASCII(length int) string {
	return string(bytesMultiRange(length, [2]byte{0x20, 0x7e + 1})) // ASCII可显示字符 32~126
}

// bytesMultiRange
func bytesMultiRange(length int, ranges ...[2]byte) []byte {
	bytes := make([]byte, 0, length)
	for i := 0; i < length; i++ {
		b := IntegerMutiRange(ranges...)
		bytes = append(bytes, b)
	}
	return bytes
}

// runesMultiRange
func runesMultiRange(length int, ranges ...[2]rune) []rune {
	runes := make([]rune, 0, length)
	for i := 0; i < length; i++ {
		r := IntegerMutiRange(ranges...)
		runes = append(runes, r)
	}
	return runes
}
